/** 
 * 预约JS
 * 整理 : fankey
 * 时间 : 2015-07-22
 */

    /**
     * 预约信息第一步进入第二步的验证输入数据是否合法
     */
    function jumpto() {
        var orderid = $('#orderid').val();
        var birthday = $("#birthday").val();
        var wedding = $('input[name="wedding"]:checked').val();
        //var wedding = 1;
        var tel = $("#tel").val();
        var email = $("#email").val();
        var region = $('input[name="user_region"]:checked').val();
        /*
            if(typeof(wedding) == 'undefined'){
            alert('请选择婚姻状况');
            return false;
        }*/

        if(typeof(wedding) == 'undefined'){
            wedding = 0;
        }

        if(tel == '') {
            alert('请输入联系手机号');
            return false;
        }

        if(tel.length!=11) {
            alert('请输入11位联系正确的手机号');
            return false;
        }

        if( wedding == undefined) {
            alert('请选择婚姻状态。');
            return false;
        }

        /* 美赞臣项目 需要选择区域 */
        if(userInfo.user_enterprise_code == 'ET20150423045715') {
            if( region == undefined ) {
                alert('请选择区域');
                return false;
            }
            window.location='index.php?action=reservation_2&orderid='+orderid+'&birthday='+birthday+'&wedding='+wedding+'&tel='+tel+'&email='+email+'&region='+region;
        }else{
            window.location='index.php?action=reservation_2&orderid='+orderid+'&birthday='+birthday+'&wedding='+wedding+'&tel='+tel+'&email='+email;
        }
    }

    //登录验证JS
    function jumptojs(){

        var orderid = $('#orderid').val();
        var birthday = $("#birthday").val();
        var user_indefiny_code = $("#user_indefiny_code").val();
        var wedding = $('input[name="wedding"]:checked').val();
        var sex = $("input[name='sex']:radio:checked").val();
        var tel = $("#tel").val();
        var email = $("#email").val();
        var region = $('input[name="user_region"]:checked').val();
        /*
        if(typeof(wedding) == 'undefined'){
            alert('请选择婚姻状况');
            return false;
        }
        */
    
        if(typeof(wedding) == 'undefined'){
            wedding = 0;
        }
        
        if(user_indefiny_code==''){
            alert('身份证必须填写');
            return false;
        }
        if( sex == undefined ){
            alert('请选择性别');
            return false;
        }
        if(tel == ''){
            alert('请输入联系手机号');
            return false;
        }

        if(tel.length!=11){
            alert('请输入11位联系正确的手机号');
            return false;
        }

        if( wedding == undefined){
            alert('请选择婚姻状态。');
            return false;
        }
        if(userInfo.user_enterprise_code == 'ET20150423045715'){
            if( region == undefined ){
                alert('请选择区域');
                return false;
            }
            window.location='index.php?action=jsreservation_2&orderid='+orderid+'&birthday='+birthday+'&wedding='+wedding+'&tel='+tel+'&email='+email+'&region='+region;
        } else {
            window.location='index.php?action=jsreservation_2&orderid='+orderid+'&birthday='+birthday+'&wedding='+wedding+'&tel='+tel+'&email='+email+'&code='+user_indefiny_code+'&sex='+sex;
        }
    }


    function submitto(){
        var orderid = $('#orderid').val();
        var birthday = $("#birthday").val();
        var wedding = $('input[name="wedding"]:checked').val();
        var tel = $("#tel").val();
        var email = $("#email").val();

        if(typeof(wedding) =='undefined') {
            wedding = 0;
        }
        
        if(tel == ''){
            alert('请输入联系手机号');
            return false;
        }
        
        if(tel.length!=11){
            alert('请输入11位手机号');
            return false;
        }
        $("#appendform").submit();
    }


    function submittojs(){
        var orderid = $('#orderid').val();
        var birthday = $("#birthday").val();
        var wedding = $('input[name="wedding"]:checked').val();
        var tel = $("#tel").val();
        var email = $("#email").val();
        var sex = $("input[name='sex']:radio:checked").val();
        var user_indefiny_code = $("#user_indefiny_code").val();
        if(user_indefiny_code=='') {
            alert('身份证必须填写');
            return false;
        }

        if( sex == undefined ){
            alert('请选择性别');
            return false;
        }

        if(tel == ''){
            alert('请输入联系手机号');
            return false;
        }

        if(tel.length!=11){
            alert('请输入11位手机号');
            return false;
        }

        if(typeof(wedding) == 'undefined') {
            wedding = 0;
        }
        
        $("#appendform").submit();

    }

    function jumpto_family() {

        var orderid = $('#orderid').val();
        var name = $('#name').val();
        var type = $('input[name="type"]:checked').val();
        var code = $('#code').val();
        var sex = $('input[name="sex"]:checked').val();
        var birthday = $("#birthday").val();
        var wedding = $('input[name="wedding"]:checked').val();
        var tel = $("#tel").val();
        var email = $("#email").val();

        if(orderid == '') {
            alert('订单号不存在');
            return false;
        }else if(name == '') {
            alert('请输入家属姓名');
            return false;
        }else if( wedding == undefined) {
            alert('请选择婚姻状态。');
            return false;
        }else if(code == '') {
            alert('请输入证件号码');
            return false;
        }else if(tel == '') {
            alert('请输入手机号');
            return false;
        }

        window.location='index.php?action=family_2&orderid='+orderid+'&name='+name+'&type='+type+'&code='+code+'&sex='+sex+'&birthday='+birthday+'&wedding='+wedding+'&tel='+tel+'&email='+email;
    }


    function jumpto_family_2(){
        var name = $('#name').val();
        var type = $('input[name="type"]:checked').val();
        var code = $('#code').val();
        var sex = $('input[name="sex"]:checked').val();
        var birthday = $("#birthday").val();
        //var wedding = $('input[name="wedding"]:checked').val();
        var tel = $("#tel").val();
        var email = $("#email").val();

        /*
        if(typeof(wedding) == 'undefined'){
        alert('请选择婚姻状况');
        return false;
        }else
        */
        if(name == ''){
            alert('请输入体检人姓名');
            return false;
        }else if(typeof(type) == 'undefined'){
            alert('请选择有效证件类型');
            return false;
        }else if(code == ''){
            alert('请输入证件号码');
            return false;
        }else if( sex == undefined){
            alert('性别必须选择');
            return false;
        }else if(tel == ''){
            alert('请输入手机号');
            return false;
        }else if(tel.length!=11){
            alert('请输入正确的手机号');
            return false;
        }else if(type==1){
            var regz = /.*[\u4e00-\u9fa5]+.*$/;
            if(code.length!=15&&code.length!=18){
                alert('请输入正确的身份证号码');
                return false;
            }

            if(-1 != code.indexOf(" ")) {
                alert('身份证号码不能包含空格');
                return false;
            }

            if(regz.test(code)) {
                alert('身份证号码不能包含中文');
                return false;
            }

            //根据填写的身份证号码，判断男女性别
            if(code.length==15) {
                var is_sex_15 = code.substring(14,15);
                if(is_sex_15%2 ==0 && sex == 1){
                    alert("您的身份证显示为女性，请勿选择男性");
                    return false;
                }else if(is_sex_15%2 !=0 && sex == 2){
                    alert("您的身份证显示为男性，请勿选择女性");
                    return false;
                }
                $("#appendform").submit();
                return true;
            }else if(code.length==18) {
                var is_sex_18 = code.substring(16,17);
                if(is_sex_18%2 ==0 && sex == 1){
                    alert("您的身份证显示为女性，请勿选择男性");
                    return false;
                }else if(is_sex_18%2 !=0 && sex == 2) {
                    alert("您的身份证显示为男性，请勿选择女性");
                    return false;
                }
                $("#appendform").submit();
                return true;
            }
        } else if(type != 1){
            if(-1 != code.indexOf(" ")) {
                alert('证件号不能包含空格');
                return false;
            }
            $("#appendform").submit();
            return true;
        } else {
            $("#appendform").submit();
            return true;
        }
    }

    /* 跳转到 家属预约第三步*/
    function jumpto_family_3(){
        var name = $('#name').val();
        var type = $('input[name="type"]:checked').val();
        var code = $('#code').val();
        var sex = $('input[name="sex"]:checked').val();
        var birthday = $("#birthday").val();
        //var wedding = $('input[name="wedding"]:checked').val();
        var tel = $("#tel").val();
        var email = $("#email").val();

        /*
        if(typeof(wedding) == 'undefined'){
            alert('请选择婚姻状况');
            return false;
        }else 
        */
        if(name == ''){
            alert('请输入体检人姓名');
            return false;
        }else if(typeof(type) == 'undefined') {
            alert('请选择有效证件类型');
            return false;
        }else if(code == '') {
            alert('请输入证件号码');
            return false;
        }else if(tel == '') {
            alert('请输入手机号');
            return false;
        }else if(tel.length!=11) {
            alert('请输入正确的手机号');
            return false;
        }else if(type==1) {
            var regz = /.*[\u4e00-\u9fa5]+.*$/;
            if(code.length!=15&&code.length!=18){
                alert('请输入正确的身份证号码');
                return false;
            }

            if(-1 != code.indexOf(" ")) {
                alert('身份证号码不能包含空格');
                return false;
            }

            if(regz.test(code)) {
                alert('身份证号码不能包含中文');
                return false;
            }
            $("#appendform").submit();
            return true;
        }else if(type != 1){
            if(-1 != code.indexOf(" ")) {
                alert('证件号不能包含空格');
                return false;
            }
            $("#appendform").submit();
            return true;
        } else {
            $("#appendform").submit();
            return true;
        }
    }


    function get_supplier_list_edit(productcode) {
        //var browser=navigator.appName;
        //var b_version=navigator.appVersion;
        //var version=b_version.split(";");
        //var trim_Version=version[1].replace(/[ ]/g,"");

        var orderid = $('#orderid').val();
        var cityid = $('#city').val();
        var project_code = $('#projectcode').val();
        var productcode = productcode;

        $("#loading").remove();
        $("#ses").append('<div id="loading" style="text-align:center; "><img src="templates/images/loading_1.gif"></div>');
        $("#store").empty();
        $("#product").empty();
        $("#jx").empty();
        $("#yytime").val('');
        $.getJSON("/index.php?action=deliver_store_dj_edit&orderid=" + orderid+"&cityid=" + cityid+"&project_code=" + project_code+"&productcode=" + productcode , function(result) {
            if (result == null) {
                $("#store").append("暂无门店数据");
            } else {
                $.each(result, function(k, v) {
                    //$("#store").append("<tr style='font-size:12px'>" + v + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + k +  "' onclick='get_product_list();get_store_ldtime();get_item_jx("+k+");'/></td></tr>");
                    //var c = k.split('-');
                    if($.browser.msie && ($.browser.version == "8.0")){
                        $("#store").prepend("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"') /></td></tr>");
                    }else{
                        $("#store").append("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"') /></td></tr>");
                    }
                });
            }
            $("#loading").remove();
        });
    }

    /** 
     * 获取员工预约门店列表信息
     */
    function get_supplier_list(productcode ) {
        //var browser=navigator.appName;
        //var b_version=navigator.appVersion;
        //var version=b_version.split(";");
        //var trim_Version=version[1].replace(/[ ]/g,"");

        var orderid = $('#orderid').val();
        var cityid = $('#city').val();
        var project_code = $('#projectcode').val();
        var  productcode = productcode;

        $("#loading").remove();
        $("#ses").append('<div id="loading" style="text-align:center; "><img src="templates/images/loading_1.gif"></div>');
        $("#store").empty();
        $("#product").empty();
        $("#jx").empty();
        $("#yytime").val('');
        $.getJSON("/index.php?action=deliver_store_dj&orderid=" + orderid+"&cityid=" + cityid+"&project_code=" + project_code+"&productcode=" + productcode , function(result) {

            if (result == null) {
                $("#store").append("暂无门店数据");
            } else {
                $.each(result, function(k, v) {
                    //$("#store").append("<tr style='font-size:12px'>" + v + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + k +  "' onclick='get_product_list();get_store_ldtime();get_item_jx("+k+");'/></td></tr>");
                    //var c = k.split('-');
                    if($.browser.msie && ($.browser.version == "8.0") ) {
                        if(userInfo.user_enterprise_code != 'ET20150602060951') {
                            $("#store").prepend("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"') /></td></tr>");
                        } else {
                            $("#store").append("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"') /></td></tr>");
                        }
                    }else{
                        $("#store").append("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"') /></td></tr>");
                    }
                });
            }

            $("#loading").remove();
        });
    }

    /** 
     * 获取员工家属的预约门店列表信息
     */
    function get_supplier_list_famliy(productcode) {
        //var browser=navigator.appName;
        //var b_version=navigator.appVersion;
        //var version=b_version.split(";");
        //var trim_Version=version[1].replace(/[ ]/g,"");

        var cityid = $('#city').val();
        var project_code = $('#projectcode').val();
        var  productcode = $('productcode').val();
        $("#store").empty();
        $("#product").empty();
        $("#jx").empty();
        $("#loading").remove();
        $("#ses").append('<div id="loading" style="text-align:center; "><img src="templates/images/loading_1.gif"></div>');

        $.getJSON("/index.php?action=deliver_store_dj_family&cityid=" + cityid+"&project_code=" + project_code+"&productcode=" + productcode  , function(result) {

            $("#yytime").val('');
            if (result == null) {
                $("#store").append("<tr><td colspan=4>暂无门店数据</td></tr>");
            } else {
                $.each(result, function(k, v) {
                    //$("#store").append("<tr  style='font-size:12px'>" + v + "<td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + k+  "' onclick='get_product_list_famliy();get_store_ldtime();get_item_jx(" + k+  ");'/></td></tr>");
                    //var c = k.split('-');
                    if($.browser.msie && ($.browser.version == "8.0") ){
                        //屏蔽诺和诺德
                        //userInfo.user_enterprise_code != 'ET20150602060951'
                        $("#store").prepend("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list_famliy();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"'); /></td></tr>");
                    }else{
                        $("#store").append("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list_famliy();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"'); /></td></tr>");
                    }

                    //$("#store").append("<tr style='font-size:12px'>" + v[0] + "</td><td><input type='radio' class='radiobtnfix' name='selectstore'  id='selectstore' value='" + v[1] +  "' onclick=sub_form();get_product_list_famliy();get_store_ldtime();get_item_jx("+v[1]+");check_info("+v[1]+",'"+productcode+"'); /></td></tr>");
                });
            }
            $("#loading").remove();
        });
    }


    /**
     * 获取员工套餐信息列表
     */
    function get_product_list() {
        var store = $('input[name="selectstore"]:checked').val();
        var project_code = $('#projectcode').val();
        var wide = $('#wide').val();
        var orderid = $('#orderid').val();
        var wedding = $('#wedding').val();
        var sex = $('#sex').val();
        $("#product").empty();
        $("#jx").empty();
        $("#yytime").val('');
        $("#loading").remove();
        $("#pses").append('<div id="loading" style="text-align:center; "><img src="templates/images/loading_1.gif"></div>');

        $.getJSON("/index.php?action=deliver_product_dj&store="+store+"&project_code=" + project_code+"&wide=" + wide+"&orderid=" + orderid+"&wedding=" + wedding+"&sex="+sex , function(result) {

            if (result == '') {
                $("#product").append("<tr ><td colspan=7>暂无套餐数据</td></tr>");
                $("#no_sa").val('1');
            } else {
                $.each(result, function(k, v) {
                    $("#product").append("<tr style='font-size:12px'><td><div align=left>" + v + "</div><td><input type='radio' class='radiobtnfix' onclick=get_item_addon();check_info("+store+",'"+k+"'); name='selectproduct'  id='selectproduct' value='" + k+  "' /></td></tr>");
                    $("#no_sa").val('0');
                });
            }

            $("#loading").remove();
        });
    }

    function sub_form(){
        //var c ='';
        //$('input[name^=pd_sa]:checked').each(function(i){
        //c += i;
        //});
        //if(c>=1){
        //屏蔽诺和诺德
        if( userInfo.user_enterprise_code != 'ET20150602060951'){
            $('#dis_show').show();
        }

        //}else{
        //  $('#dis_show').hide();
        //}
    }

    /**
     * 获取员工家属套餐列表
     */
    function get_product_list_famliy() {
        var store = $('input[name="selectstore"]:checked').val();
        var project_code = $('#projectcode').val();
        var sex = $('#sex').val();
        var wedding = $('#wedding').val();
        var product_code = $('#product_code').val();
        var jsonstr = product_code.split(",");

        $("#product").empty();
        $("#jx").empty();
        $("#yytime").val('');
        $("#loading").remove();
        $("#pses").append('<div id="loading" style="text-align:center; "><img src="templates/images/loading_1.gif"></div>');

        $.getJSON("/index.php?action=deliver_product_dj_famliy&store="+store+"&project_code=" + project_code+"&sex=" + sex +"&wedding=" + wedding , function(result) {

            if (result == '') {
                $("#product").append("<tr ><td colspan=7>暂无套餐数据</td></tr>");
                $("#no_sa").val('1');
            } else {
                $.each(result, function(k, v) {
                    if(jsonstr.length == 1){
                        if(k == jsonstr[0]){
                            $("#product").append("<tr style='font-size:12px'><td><div align=left>" + v + "</div><td><input type='radio' class='radiobtnfix' onclick=get_item_addon_family();check_info("+store+",'"+k+"'); name='selectproduct'  id='selectproduct' value='" + k+  "' /></td></tr>");
                        }
                    }else if( project_code == 'PJ20150423105754'){
                        //15年美赞臣
                        $("#product").append("<tr style='font-size:12px'><td><div align=left>" + v + "</div><td><input type='radio' class='radiobtnfix' onclick=get_item_addon_family();check_info("+store+",'"+k+"'); name='selectproduct'  id='selectproduct' value='" + k+  "' /></td></tr>");
                    }else if(jsonstr.length >= 2){
                        if(k == jsonstr[0] || k == jsonstr[1]){
                            $("#product").append("<tr style='font-size:12px'><td><div align=left>" + v + "</div><td><input type='radio' class='radiobtnfix' onclick=get_item_addon_family();check_info("+store+",'"+k+"'); name='selectproduct'  id='selectproduct' value='" + k+  "' /></td></tr>");
                        }
                    }

                    $("#no_sa").val('0');
                });
            }

            $("#loading").remove();
            //$("input[name='selectproduct'][value='"+jsonstr[0]+"'").attr("checked",true);
            //get_item_addon_family();
        });
    }


    /* 门店套餐绑定温馨提醒 */
    function check_info(s,p){
        $.getJSON("/index.php?action=find_product_store&store="+s+"&product_code=" + p, function(result) {

            if(result!=null){
                alert(result);
            }
            //$("#loading").remove();
        });
    }


    function get_store_ldtime() {

        $('#freeset').html('');
            var store = $('input[name="selectstore"]:checked').val();
            if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }

        var S = {};
        S.data = {
            store : store
        };

        $('#ldtime').html('');
        $.ajax( {
            url : "/index.php?action=getldtime",
            type : "POST",
            data : S.data,
            cache : false,
            dataType : "json",
            success : function(json) {
                // alert(json.m);
                if (json.c == 'error') {
                    alert('系统出错,请稍后在试');
                } else if (json.c == 'success') {
                    if(json.m != 0 ){
                        $('#ldtime').html('预约请至少提前&nbsp;<b>'+json.m+'&nbsp;</b>个工作日');
                        }
                    if(json.yg != '' ){
                        $('#ygdiv').show();
                        $('#ygbg').html(json.yg);
                    }else{
                        $('#ygdiv').show();
                        $('#ygbg').html('');
                    }
                // alert(json.m);
                }
            },
            error : function() {
                alert('出错了');
            }
        });
    }


    function get_free_time() {

        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var fam = 0;
        // var product = $('input[name="selectproduct"]:checked').val();
        if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == ''){
            alert('项目编码空');
            return false;
        }

        var S = {};
        S.data = {
            store : store,
            projectcode : projectcode,
            fam:fam
        };
        $('#freeset').html('');
        $.ajax( {
            url : "/index.php?action=getfree",
            type : "POST",
            data : S.data,
            cache : false,
            dataType : "json",
            success : function(json) {
                // alert(json.m);
                if (json.c == 'error') {
                    //alert('系统出错,请稍后在试');
                    if(json.m == 'nostore') {
                        alert('请选择一家门店');
                    }else if(json.m == 'noproduct'){
                        alert('请选择您需要的套餐');
                    }
                } else if (json.c == 'success') {
                    if(json.m =='empty'){
                        alert('近1个月无可约时间段');
                    }else{
                        $('#freeset').html(json.m);
                    }
                    // alert(json.m);
                }
            },
            error : function() {
                alert('出错了');
            }
        });
    }


    function get_free_time_famliy() {

        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var product = $('#productcode').val();
        var fam = 1;
        if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == ''){
            alert('项目编码空');
            return false;
        }else if(product == '' ){
            alert('请选择您所需要的套餐');
            return false;
        }
        var S = {};
        S.data = {
            store : store,
            projectcode : projectcode,
            product : product,
            fam:fam
        };
        $('#freeset').html('');
        $.ajax( {
            url : "/index.php?action=getfree",
            type : "POST",
            data : S.data,
            cache : false,
            dataType : "json",
            success : function(json) {
                // alert(json.m);
                if (json.c == 'error') {
                    //alert('系统出错,请稍后在试');
                    if(json.m == 'nostore') {
                        alert('请选择一家门店');
                    }else if(json.m == 'noproduct') {
                        alert('请选择您需要的套餐');
                    }
                } else if (json.c == 'success') {
                    if(json.m =='empty'){
                        alert('近1个月无可约时间段');
                    }else{
                        $('#freeset').html(json.m);
                    }
                // alert(json.m);
                }
            },
            error : function() {
                alert('出错了');
            }
        });
    }


    function get_edit_free_time_famliy() {

        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var product = $('#productcode').val();
        var fam = 0;
        if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == ''){
            alert('项目编码空');
            return false;
        }else if(product == '' ){
            alert('请选择您所需要的套餐');
            return false;
        }
        var S = {};
        S.data = {
            store : store,
            projectcode : projectcode,
            product : product,
            fam:fam
        };
        $('#freeset').html('');
        $.ajax( {
            url : "/index.php?action=getfree",
            type : "POST",
            data : S.data,
            cache : false,
            dataType : "json",
            success : function(json) {
                // alert(json.m);
                if (json.c == 'error') {
                    //alert('系统出错,请稍后在试');
                    if(json.m == 'nostore') {
                        alert('请选择一家门店');
                    }else if(json.m == 'noproduct') {
                        alert('请选择您需要的套餐');
                    }
                } else if (json.c == 'success') {
                    if(json.m =='empty'){
                        alert('近1个月无可约时间段');
                    }else{
                        $('#freeset').html(json.m);
                    }
                    // alert(json.m);
                }
            },
            error : function() {
                alert('出错了');
            }
        });
    }


    function filldate(date_select) {
        $('#yytime').val(date_select);
        $('#freeset').html('');
    }


    function submit_append() {
        var city = $('#city').val();
        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var product =  $('input[name="selectproduct"]:checked').val();
        var yytime = $('#yytime').val();

        if(city == ''){
            alert('请选择城市');
            return false;
        }else if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == '' ){
            alert('项目编码不对称');
            return false;
        }else if(typeof(product) == 'undefined' ){
            alert('请选择您所需要的套餐');
            return false;
        }else if(yytime == '' ){
            alert('请输入预约时间');
            return false;
        }

        if( userInfo.user_enterprise_code == 'ET20150423045715'){
            //美赞成
            if( product == 'PD20150514135009' || product == 'PD20150514134851' || product == 'PD20150514134152'){
            //北京朝阳无须选加项
            }else{
                if( $("input[name='checkbox_value[]']:checked").length == 0){
                    alert('加项必须选择一个');
                    return false;
                }
                if( userInfo.user_wide == 1){
                    if( $("input[name='checkbox_value[]']:checked").length > 1){
                        alert('加项只能选一个');
                        return false;
                    }
                }
            }
        }

        /* 2015亿滋项目必须要选择一个加项 */
        if(userInfo.user_enterprise_code == 'ET20150721072029'){
            if( $("input[name='checkbox_value[]']:checked").length != 1) {
                alert('套餐加项只能选择一个');
                return false;
            }
        }

        /* 2015测试项目必须要选择一个加项 */
        // if(userInfo.user_enterprise_code == 'ET20151215121342'){
        //  if( $("input[name='checkbox_value[]']:checked").length != 1) {
        //      alert('套餐加项只能选择一个');
        //      return false;
        //  }
        // }

        /* 2015沃尔玛项目必须要选择一个加项 */
        if(userInfo.user_enterprise_code == 'ET20150906092305'){
            //套餐A与C 不做限制
            if(product=='PD20150906133831' || product=='PD20150906151239' || product=='PD20150906152046' || product=='PD20150906154606' || product=='PD20150906155253' || product=='PD20150906155656'){
                if( $("input[name='checkbox_value[]']:checked").length > 1) {
                    alert('加项套餐只能选择一个!');
                    return false;
                }
            } else {
                if( $("input[name='checkbox_value[]']:checked").length != 1) {
                    alert('加项套餐只能选择一个!');
                    return false;
                }   
            }
        }

        /* 2015捷成项目必须要选择一个加项 */
        if( userInfo.user_enterprise_code == 'ET20151026100404' ){
            //捷成体检套餐必选一个加项
            if( product == 'PD20151029145554' ||  product == 'PD20151029181124' ||  product == 'PD20151029181207' ) {
                if( $("input[name='checkbox_value[]']:checked").length != 1) {
                    alert('套餐加项只能选择一个');
                    return false;
                }
            }
        }

        $("#appendform").submit();
    }

    function submit_append_family() {
        var city = $('#city').val();
        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var yytime = $('#yytime').val();
        var product =  $('input[name="selectproduct"]:checked').val();

        if(city == ''){
            alert('请选择城市');
            return false;
        }else if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == '' ){
            alert('项目编码不对称');
            return false;
        }else if(typeof(product) == 'undefined' ){
            alert('请选择您所需要的套餐');
            return false;
        }else if(yytime == '' ){
            alert('请输入预约时间');
            return false;
        }

        if( userInfo.user_enterprise_code == 'ET20150423045715'){
            //美赞成
            if( $("input[name='checkbox_value[]']:checked").length == 0){
                alert('加项必须选择一个');
                return false;
            }else if( $("input[name='checkbox_value[]']:checked").length > 1){
                alert('加项只能选一个');
                return false;
            }
        }

        /* 2015亿滋项目必须要选择一个加项 */
        if(userInfo.user_enterprise_code == 'ET20150721072029'){
            if( $("input[name='checkbox_value[]']:checked").length != 1) {
                alert('套餐加项只能选择一个');
                return false;
            }
        }

        /* 2015测试项目必须要选择一个加项 */
        if(userInfo.user_enterprise_code == 'ET20151215121342'){
            if( $("input[name='checkbox_value[]']:checked").length != 1) {
                alert('套餐加项只能选择一个');
                return false;
            }
        }

        /* 2015沃尔玛项目必须要选择一个加项 */
        if(userInfo.user_enterprise_code == 'ET20150906092305'){
            //套餐A与C 不做限制
            if(product=='PD20150906133831' || product=='PD20150906151239' || product=='PD20150906152046' || product=='PD20150906154606' || product=='PD20150906155253' || product=='PD20150906155656'){
                if( $("input[name='checkbox_value[]']:checked").length > 1) {
                    alert('加项套餐只能选择一个!');
                    return false;
                }
            } else {
                if( $("input[name='checkbox_value[]']:checked").length != 1) {
                    alert('加项套餐只能选择一个!');
                    return false;
                }   
            }
        }

        /* 2015捷成项目必须要选择一个加项 */
        if(userInfo.user_enterprise_code == 'ET20151026100404'){
            //捷成体检套餐必选一个加项
            if( product == 'PD20151029145554' ||  product == 'PD20151029181124' ||  product == 'PD20151029181207' ) {
                if( $("input[name='checkbox_value[]']:checked").length != 1) {
                    alert('套餐加项只能选择一个');
                    return false;
                }
            }
        }
        
        $("#appendform").submit();
    }


    function submit_append_edit() {
    
        var city = $('#city').val();
        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var product =  $('input[name="selectproduct"]:checked').val();
        var yytime = $('#yytime').val();
        var sa = $("#no_sa").val();
        var p_code =  $('#productcode').val();
        if(product=''){
            product = p_code;
        }

        if(city == ''){
            alert('请选择城市');
            return false;
        }else if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == '' ){
            alert('项目编码不对称');
            return false;
        }else if(typeof(product) == 'undefined'){
            alert('请选择您所需要的套餐');
            return false;
        }else if(yytime == '' ){
            alert('请输入预约时间');
            return false;
        }else if(sa==1){
            alert('抱歉，该门店不支持您所选的加项，请更换其他门店');
            return false;
        }
        //else if(yytime == $('#oldyytime').val() && store == $('#oldstore').val() && product == $('#oldproduct').val() ){
        //alert('您没有任何改约操作');
        //return false;
        //}

        $("#appendform").submit();
    }


    function submit_append_edit_js() {
        var city = $('#city').val();
        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var product =  $('input[name="selectproduct"]:checked').val();
        var yytime = $('#yytime').val();
        var sa = $("#no_sa").val();
        var p_code =  $('#productcode').val();
        if(product='') {
            product = p_code;
        }

        if(city == '') {
            alert('请选择城市');
            return false;
        }else if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == '' ){
            alert('项目编码不对称');
            return false;
        }else if(typeof(product) == 'undefined'){
            alert('请选择您所需要的套餐');
            return false;
        }else if(yytime == '' ){
            alert('请输入预约时间');
            return false;
        }else if(sa==1){
            alert('抱歉，该门店不支持您所选的加项，请更换其他门店');
            return false;
        }
        //else if(yytime == $('#oldyytime').val() && store == $('#oldstore').val() && product == $('#oldproduct').val() ){
        //alert('您没有任何改约操作');
        //return false;
        //}
        $("#appendform").submit();
    }


    function submit_append_edit_family() {
        var city = $('#city').val();
        var store = $('input[name="selectstore"]:checked').val();
        var projectcode = $('#projectcode').val();
        var yytime = $('#yytime').val();
        var no_sa =  $('#no_sa').val();
        if(city == ''){
            alert('请选择城市');
            return false;
        }else if(typeof(store) == 'undefined'){
            alert('请选择一家门店');
            return false;
        }else if(projectcode == '' ){
            alert('项目编码不对称');
            return false;
        }else if(yytime == '' ){
            alert('请输入预约时间');
            return false;
        }else if(no_sa == '1' ){
            alert('抱歉，该门店不支持加项,请更换其他门店');
            return false;
        }
        //else if(yytime == $('#oldyytime').val() && store == $('#oldstore').val()  ){
        //alert('您没有任何改约操作');
        //return false;
        //}
        $("#appendform").submit();
    }


    function emptyval(){
        $("#yytime").val('');
    }

    //取消预约
    function cancle_order(id){
        if(confirm('确定取消预约么?') == false ){
            return false;
        }

        var js = $('#js').val();
        window.location.href="/index.php?action=delappend&orderid="+id+"&js="+js;
    }


    function submit_pay() {
        var is_checked = $("input[type='checkbox']").is(':checked');
        if (!is_checked) {
            alert('请选择一笔支付订单！');
            return false;
        }

        $("#appendform").submit();
    }


    function setprice(){
        /* 
        var is_checked = $("input[type='checkbox']").is(':checked');
        var pcc = $('#totalprice').val();
        var realprice = pcc-pc;
        $('#pcc').html('<font size="+1">总金额：￥'+realprice+'</font>');
        $('#totalprice').val(realprice);
        */
        var pcc = 0;
        $("input[name='checkbox_value[]']").each(function(){
            if($(this).attr("checked")){
                pcc =pcc+parseInt($('input[name="checkbox_value[]"]:checked').attr('ss'));
            }
        });

        $('#pcc').html('<font size="+1">总金额：￥'+pcc+'</font>');
        if(pcc == 0){
            $('#paygo').html('');
        }else{
            $('#paygo').html('<a href="javascript:void(0);"  onClick="submit_payoff()" class="blue" target="_self"><img src="templates/images/go.jpg"></a>');
        }
    }